package com.gy.flink;


import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;
import java.util.List;

public class StreamingSourceCollection {

    public static void main(String[] args) throws Exception {
        //获取环境变量
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        //模拟数据
        List<String> data = Arrays.asList(
                "hadoop",
                "spark",
                "flink"
        );
        //获取数据源
        DataStreamSource<String> dataStream = env.fromCollection(data);
        //transformation
        SingleOutputStreamOperator<String> mapDataStream = dataStream.map(new MapFunction<String, String>() {
            @Override
            public String map(String s) throws Exception {
                return "gy_" + s;
            }
        });
        //结果处理
        mapDataStream.print().setParallelism(1);
        //启动程序
        env.execute("first job name");


    }
}
